package com.dwxt.community.admin.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.community.admin.service.CommunityServiceAdmin;
import com.dwxt.community.entity.Community;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cms/community")
public class CommunityControllerAdmin {

    @Autowired
    private CommunityServiceAdmin communityServiceAdmin;

    @RequestMapping("/selectCommunityPage")
    public BaseResult selectCommunityPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Community> communities = communityServiceAdmin.selectCommunityList();
        PageInfo<Community> pageInfo=new PageInfo<>(communities);
        return BaseResult.ok(pageInfo);
    }

    @RequestMapping("/createOrUpdateCommunity")
    public BaseResult createOrUpdateCommunity(Community community){
        communityServiceAdmin.createOrUpdateCommunity(community);
        return BaseResult.ok();
    }
}
